#pragma once


typedef unsigned int FS_TYPE;

#define FS_TYPE_GENERAL     1
#define FS_TYPE_JFFS2       2
#define FS_TYPE_YAFFS       3
#define FS_TYPE_YAFFS2      4


#define LINUX_MAGIC    0x016f2818
#define CRAMFS_MAGIC   0x28cd3d45
#define JFFS2_MAGIC    0x1985

#define LINUX_MAGIC_OFFSET	0x24
#define GBIOS_MAGIC_OFFSET  0x4
#define JFFS2_MAGIC_OFFSET  0x0

#define O_CREAT   (1)
#define O_RDWR    (1)

struct File
{
	// ULONG     nCurPos; // fixme: to restore
	ULONG     nFileSize;
	char      szFileName[MAX_FILE_NAME_LEN];

	struct BlockBuff mBlkBuf;

	struct Partition      *pHost;
	const struct FileOps  *pFops;
};


int open(const char *pchPath, UINT32 dwFlags);

int read(int fd, void *pBuf, ULONG len);

int write(int fd, void *pBuf, ULONG len);

int close(int fd);


struct FileOps
{
	int (*Open)(const char *, UINT32);
	int (*Read)(struct File*, void *, ULONG);
	int (*Write)(struct File*, void *, ULONG);
	int (*Close)(struct File*);
};


struct FileSys
{
	FS_TYPE nType;
	// ULONG nDefBuffSize;

	struct ListNode nodeFileSys;

	const struct FileOps *pFops;
};


int FileSysRegister(struct FileSys *pfs);

struct ImageCache *GuImageCacheGet(PART_TYPE nType);

BOOL GuImageCacheCheck(struct Partition *pPart);


